﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace PlusPlusPaint.GUI
{
    public partial class ColourBox : Panel
    {
        Color colour;

        public Color Colour
        {
            get
            {
                return colour;
            }
            set
            {
                colour = value;
                this.BackColor = value;
                this.ColourUpdated(this, EventArgs.Empty);
            }
        }

        public event EventHandler ColourUpdated;

        public ColourBox(Color c)
        {
            this.BorderStyle = BorderStyle.FixedSingle;
            this.Size = new Size(14, 14);
            colour = c;
            this.BackColor = c;
            this.DoubleClick += openColorDialog;
        }

        private void openColorDialog(object sender, EventArgs ea)
        {
            ColorDialog cd = new ColorDialog();
            cd.AllowFullOpen = true;
            cd.ShowHelp = true;
            cd.Color = this.Colour;
            if (cd.ShowDialog() == DialogResult.OK)
            {
                this.Colour = cd.Color;
            }
        }
    }
}
